package com.webcamtracker.ms2;

import java.awt.*;

public class SpaceTransforms {
    public static class SpaceCoords {
        double min;
        double max;
        double distance;

        public SpaceCoords(double min, double max) {
            this.max = max;
            this.min = min;
            this.distance = this.max - this.min;
        }
    }

    public static class SpaceCoordsTransform {
        SpaceCoords source;
        SpaceCoords target;
        double quotient;

        public SpaceCoordsTransform(SpaceCoords source, SpaceCoords target) {
            this.source = source;
            this.target = target;
            quotient = target.distance / source.distance;
        }

        public double map(double sourceCoords) {
            return target.min + ((sourceCoords - source.min) * quotient);
        }
    }

    public static class SpaceCoords2d {
        SpaceCoords x;
        SpaceCoords y;

        public SpaceCoords2d(Point min, Point max) {
            this.x = new SpaceCoords(min.x, max.x);
            this.y = new SpaceCoords(min.y, max.y);
        }
    }

    public static class SpaceCoords2dTransform {
        SpaceCoordsTransform transformX;
        SpaceCoordsTransform transformY;

        public SpaceCoords2dTransform(SpaceCoords2d source, SpaceCoords2d target) {
            transformX = new SpaceCoordsTransform(source.x, target.x);
            transformY = new SpaceCoordsTransform(source.y, target.y);
        }

        public Point map(Point point) {
            return new Point((int) transformX.map(point.x), (int) transformY.map(point.y));
        }
    }
}
